<template>
	<view class="page">
		<view class="page_header"><navigation defaultButton="back">高龄津贴</navigation></view>
		<scroll-view class="page_scroll" scroll-y="true" scroll-with-animation="true" enable-back-to-top="true">
			<image class="header_image-bg" @tap="photograph()" src="../../../static/images/777.png" mode="aspectFit"></image>
			<view class="header_text-hint">津贴领取需按照每个季度进行审核</view>
			<!-- <image class="header_image-hint" src="https://images-vx.oss-cn-beijing.aliyuncs.com/images-vx/allowanceAudit_header02.png" mode="aspectFit"></image> -->
			<view class="form_panel">
				<view class="form-item">
					<view class="form-item__name disabled_name">
						高龄津贴发放地
					</view>
					<view class="form-item__value">
						{{detail.regionName}}
					</view>
				</view>
				<view class="form-item">
					<view class="form-item__name disabled_name">待遇发放标准</view>
					<view class="form-item__value"><view class="form-item__value-input">{{userInfo.money||0}}元/月</view></view>
				</view>
				<view class="form-item">
					<view class="form-item__name disabled_name">
						高龄津贴发放卡号
					</view>
					<view class="form-item__value">
						{{detail.allowanceCarCode}}
					</view>
				</view>
				<view class="form-item">
					<view class="form-item__name disabled_name">
						卡号归属银行
					</view>
					<view class="form-item__value">
						{{detail.allowanceCarAddress}}
					</view>
				</view>
				
				<!-- <form-input type="number" name="人员编号" v-model="detail.allowanceCode" :value="detail.allowanceCode"  :disabled="true" placeholder=""></form-input>
				<form-input type="number" name="高龄津贴发放地" v-model="detail.regionName" :disabled="true" placeholder=""></form-input>
				<view class="form-item">
					<view class="form-item__name disabled_name">待遇发放标准</view>
					<view class="form-item__value"><view class="form-item__value-input">{{userInfo.money}}元/月</view></view>
				</view>
				<form-input type="number" name="高龄补贴发放卡号" v-model="detail.allowanceCarCode" :disabled="true" placeholder=""></form-input>
				<form-input type="number" name="卡号归属银行 " v-model="detail.allowanceCarAddress" :disabled="true" placeholder=""></form-input> -->
				<view class="form-item">
					<view class="form-item__name">认证模版照片</view>
					<view class="form-item__value"><view class="form-item__value-input"></view></view>
				</view>
				<view class="photo_panel">
					<image
						class="form-item__value-image"
						:src="detail.imageOld"
						mode="aspectFill"
					></image>
				</view>
				<view v-if="userInfo.allowanceState != enums['津贴状态']['已过期'] && detail.image">
					<view class="form-item">
						<view class="form-item__name">认证照片</view>
						<view class="form-item__value"><view class="form-item__value-input"></view></view>
					</view>
					<view class="photo_panel">
						<image class="form-item__value-image" mode="aspectFill" :src="detail.image"></image>
					</view>
				</view>
				<view v-if="userInfo.allowanceState == enums['津贴状态']['已过期']">
					<view class="form-item" v-if="userInfo.allowanceState == enums['津贴状态']['已过期']">
						<view class="form-item__name">认证照片</view>
						<view class="form-item__value"><view class="form-item__value-input"></view></view>
					</view>
					<view class="photo_panel" @tap="photograph()" v-if="userInfo.allowanceState == enums['津贴状态']['已过期']">
						<image v-if="!model.image" class="form-item__value-image" src="https://images-vx.oss-cn-beijing.aliyuncs.com/images-vx/photo_icon.png" mode=""></image>
						<image v-else class="form-item__value-image" mode="aspectFill" :src="model.image"></image>
					</view>
				</view>
			
				<button class="page_btn" v-if="userInfo.allowanceState == enums['津贴状态']['已过期']" hover-class="page_btn-hover" @tap="submit">确认提交</button>
			</view>
		</scroll-view>
	</view>
</template>

<script>
import { HTTP_SERVER_URL } from '@/config';
import * as modelApi from '@/api/userApi/model.js';
export default {
	data() {
		return {
			enums: this.$enums,
			HTTP_SERVER_URL,
			userInfo: this.$store.getters.getUserInfo,
			detail: {
			},
			model: {
				image: ''
			}
		};
	},
	onShow() {
		this.queryAllowance();
		this.userInfo=uni.getStorageSync('open')
	},
	methods: {
		
		submit(){
			modelApi
				.updateAllowance(this.model)
				.then(res => {
					if (res.code === 0) {
						uni.showToast({
							mask:true,
							title: '提交成功',
							duration: 1500
						});
						setTimeout(() => {
							uni.switchTab({
								url: '/pages/index/index'
							});
						}, 1600);
					}
				})
				.catch(e => {
					if(e.msg){
					uni.showToast({
						title: e.msg,
						icon: 'none',
						duration: 1000
					});
					}else{
						uni.showToast({
							title: e.message,
							icon: 'none',
							duration: 1000
						});
					}
				});
		},
		queryAllowance() {
			this.userInfo = uni.getStorageSync('open');
			uni.request({
				url:HTTP_SERVER_URL+'/aged/user/queryAllowance',
				header: {
					'token': this.userInfo.jwt
				},
				method:'POST',
				success:(res)=>{
					
					this.detail=res.data.data
					console.log('detail:',this.detail)
				},
				fail(err) {
					console.log('失败',err)
					
				}
				
				
			})
			// modelApi
			// 	.queryAllowance()
			// 	.then(res => {
			// 		if (res.code === 0) {
			// 			this.detail = res.data;
			// 			console.log('resssssss',this.detail)
			// 		}
			// 	})
			// 	.catch(e => {
			// 		uni.showToast({
			// 			title: 'onshow',
			// 			icon: 'none',
			// 			duration: 1000
			// 		});
			// 	});
		},
		photograph(type) {
			let self = this;
			uni.chooseImage({
				count: 1,
				sourceType: ['camera'],
				sizeType: ['compressed', 'original'],
				success: res => {
					let url = '/institute/service-image/addImage';
					// #ifdef APP-PLUS || MP-WEIXIN
					url = HTTP_SERVER_URL + url;
					// #endif
					uni.uploadFile({
						url,
						filePath: res.tempFilePaths[0],
						name: 'file',
						success: uploadRes => {
							this.$set(this.model, 'image', JSON.parse(uploadRes.data).data);
							console.log(this.model.image)
						},
						fail: uploadErr => {
							uni.showToast({
								title: '上传失败',
								icon: 'none',
								duration: 2000
							});
						}
					});
				}
			});
		}
	}
};
</script>

<style lang="stylus">
.item
	display flex
	justify-content space-between
.page_scroll
	position absolute
	top calc(120rpx + var(--status-bar-height))
	right 0rpx
	bottom 0rpx
	left 0rpx
.header_image-bg
	width 100%
	height 225rpx
.header_text-hint
	font-size 24rpx
	font-family PingFang SC
	font-weight 400
	color #666666
	padding 30rpx 0rpx
	text-align center
.header_image-hint
	width 100%
	height 170rpx
.form_panel
	border-top 15rpx solid rgb(243, 243, 243)
	box-sizing border-box
	padding 0rpx 30rpx
	background-color #FFFFFF
	.form-item
		.form-item__name
			color rgba(102, 102, 102, 1)
		.form-item__value
			color rgba(102, 102, 102, 1)
.page_btn 
	margin-top 30rpx
	margin-bottom 30rpx
</style>
